package com.winchain.chainbill.bill.biz.send.rx;

import com.shell.bee.base.utils.DateUtil;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.governor.modules.message.keyword.SysSndBatchKeyword;
import com.winchain.chainbill.bill.biz.BatchSendEvent;
import com.winchain.chainbill.bill.biz.send.vo.BillImpt;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Component;

@Component
public class BillBatchMsgSubscriber extends OnErrorNotImplementedSubscriber<BatchSendEvent> {
	public void onApplicationEvent(BatchSendEvent t) {
		List<BillImpt> impts = t.getImpts();
		BigDecimal bd = new BigDecimal("0");
		Set<String> set = new HashSet();
		BillImpt impt;
		for (Iterator localIterator = impts.iterator(); localIterator.hasNext();) {
			impt = (BillImpt) localIterator.next();
			bd = bd.add(new BigDecimal(impt.getBillAmt()));
			set.add(impt.getSellerNm());
		}
		StringBuffer sb = new StringBuffer();
		for (String s : set) {
			sb.append(s);
			sb.append("��");
		}
		String template = "MT01202";
		SysSndBatchKeyword keyWord = new SysSndBatchKeyword();
		keyWord.setBillAmt(String.valueOf(bd));
		keyWord.setSellerNms(sb.toString().substring(0, sb.toString().length() - 1));
		keyWord.setSndDate(DateUtil.parseDate(DateUtil.getSystemDateTime(), "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"));
		keyWord.setContactorName(CommonDataUtil.getUserName());
		String senderId = CommonDataUtil.getUserId();

		MessageSender.sendMessageByTmpl(senderId, template, keyWord, CommonDataUtil.getCurEntId());
	}
}
